﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using System;
using UnityEngine.Networking;

public class MyQualitySettings : MonoBehaviour
{    
    public UniversalRenderPipelineAsset highQualityUniversalRenderPipelineAsset;
    public UniversalRenderPipelineAsset mediumQualityUniversalRenderPipelineAsset;
    public UniversalRenderPipelineAsset lowQualityUniversalRenderPipelineAsset;

    public static MyQualitySettings Instance;
    void Awake()
    {
        Instance = this;
    }

    public void SetHighQuality()
    {
        GraphicsSettings.renderPipelineAsset = highQualityUniversalRenderPipelineAsset;
    }
    
    public void SetMediumQuality()
    {
        GraphicsSettings.renderPipelineAsset = mediumQualityUniversalRenderPipelineAsset;
    }

    public void SetLowQuality()
    {
        GraphicsSettings.renderPipelineAsset = lowQualityUniversalRenderPipelineAsset;
    }

    public void GetRemoteFileSize(string url,Action<int> callback)
    {
        StartCoroutine(GetFileSize(url,callback));
    }

    IEnumerator GetFileSize(string url,Action<int> callback)
    {
        UnityWebRequest headRequest = UnityWebRequest.Head(url);
        //开始与远程服务器通信。
        yield return headRequest.SendWebRequest();
 
        if (!string.IsNullOrEmpty(headRequest.error))
        {
            // Debug.LogError("获取不到资源文件");
            callback(0);
            yield break;
        }
        //获取文件总大小
        int totalLength = int.Parse(headRequest.GetResponseHeader("Content-Length"));
        // Debug.Log("获取大小" + totalLength);
        callback(totalLength);
    }
}
